<?php
//ini_set('display_errors',1);
//ini_set('display_startup_erros',1);
error_reporting(0);

ini_set('post_max_size', '20M');
ini_set('upload_max_filesize', '20M');

session_start();
$access_control = "3tgbuh9gbufwd";

include_once "../controle/db.php";
include_once "../controle/valida.php";
include_once "../controle/funcoes.php";
include_once "../class/config.php";
include_once "../class/instituicao.php";
include_once "../class/concurso.php";
include_once "../class/cargo.php";
include_once "../class/inscrito.php";
include_once "../class/inscrito_concurso.php";
include_once "../class/boleto.php";
include_once "../class/edital.php";
include_once "../class/resultado.php";
include_once "../class/ensalamento.php";
include_once "../class/recurso.php";
include_once "../class/recurso_resposta.php";
include_once "../class/transacao.php";
include_once "../class/log.php";

function login(){
    $login = addslashes($_POST["login"]);
    $senha = md5(addslashes($_POST["senha"]));
    
    $erro = 0;
    $sql = "select * from usuario where login = '$login' and senha = '$senha' and bloqueado = 0";
    $db = new db(config::$driver);
    $con = $db->conecta();
    $result = $db->query($sql, $con);
    $db->close($con);
    $usuario = $db->fetch_array($result);

    if($usuario){
        if($usuario["bloqueado"] == 0){
            $_SESSION["klcadm_id"]    = $usuario["id"];
            $_SESSION["klcadm_nome"]  = $usuario["nome"];
            $_SESSION["klcadm_login"] = $usuario["login"];
            $_SESSION["klcadm_senha"] = $usuario["senha"];
            
            header("location: ".config::$url."admin/");
            echo "
            <meta http-equiv='refresh' content='0; url=".config::$url."admin/'>";
        }else{
            echo "
                <script>alert('Usuário bloqueado!')</script>";
        }
    }else{
        $erro = 1;
        echo "
                <script>alert('Usuário não encontrado!')</script>";
    }
    
    if($erro == 0){
        header("location: index.php");
        return 1;
    }else{
        return 0;
    }
}

function logado(){
    if($_SESSION["klcadm_id"]    != NULL && 
       $_SESSION["klcadm_nome"]  != NULL && 
       $_SESSION["klcadm_login"] != NULL && 
       $_SESSION["klcadm_senha"] != NULL){
        return 1;
    }else{
        return 0;
    }
}

function logout(){
    $_SESSION["klcadm_id"]    = NULL;
    $_SESSION["klcadm_nome"]  = NULL;
    $_SESSION["klcadm_login"] = NULL;
    $_SESSION["klcadm_senha"] = NULL;
    
    header("location: index.php");
}

?>
